package com.css.apps.base.org.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.base.log.model.LogConstant;
import com.css.apps.base.log.model.LogPart;
import com.css.apps.base.org.model.SSysOrgTree;
import com.css.core.configuration.Environment;
import com.css.db.query.TransactionCache;
import com.css.util.Ajax;
import com.css.util.Json;
import com.css.util.Messages;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ModelDriven;

/**
 * 自定义组织结构树保存
 * 
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class AddCustomOrgTree extends AdminAction implements ModelDriven {

	private static Log log = LogFactory.getLog(DirCustom.class);
	private SSysOrgTree item;

	public AddCustomOrgTree() {
		this.item = new SSysOrgTree();
	}

	@Override
	protected String adminGo() {
		TransactionCache tx = null;
		try {
			tx = new TransactionCache();
			tx.save(item);
			tx.commit();

			LogPart htlp = new LogPart();
			htlp.setOpObjType(SSysOrgTree.class.getName());
			htlp.setOpObjId(item.getUuid());
			htlp.setOpType(LogConstant.LOG_TYPE_ADD);
			htlp.setLogLevel(LogConstant.LOG_LEVEL_COMMON);
			htlp.setLogData(Json.object2json(item));
			htlp.save();
			result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS, Messages.getString("systemMsg.success"), item);
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			setMessage(Messages.getString("systemMsg.exception"));
			return Action.ERROR;
		}
	}

	@Override
	public Object getModel() {
		return item;
	}

	public SSysOrgTree getItem() {
		return item;
	}

	public void setItem(SSysOrgTree item) {
		this.item = item;
	}
}
